fix: Windows homedir, multi-session MCP, GPU override, collection routing#235
Open
fix: Windows homedir, multi-session MCP, GPU override, collection routing#235
Conversation
…ting - fix(store): use os.homedir() instead of process.env.HOME || "/tmp" On Windows cmd.exe, HOME is not set, causing QMD to write its index to /tmp/.cache/qmd/ instead of the user's home directory. - feat(llm): add QMD_GPU env var to override GPU backend Allows forcing cuda, metal, vulkan, or CPU (false/off/0) when the auto-detected GPU fails (e.g., CUDA version mismatch with pre-built binaries). - fix(mcp): per-session transport for HTTP server Each client now gets its own transport + McpServer instance, sharing one SQLite store. Previously, multiple clients (e.g., several Claude Code instances) sharing one HTTP daemon would conflict because they shared a single transport. - feat(mcp): URL-based collection routing (/mcp/COLLECTION) Connecting to /mcp/RAMP scopes all searches to the RAMP collection. Enables per-project collection scoping when using HTTP transport, since env vars cannot be passed per-session to a shared daemon. Also supports QMD_COLLECTION env var for stdio transport.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Four improvements for Windows compatibility, multi-client HTTP server stability, GPU troubleshooting, and per-project collection scoping.
1. Fix: Windows home directory resolution
src/store.tsdetermined the home directory withprocess.env.HOME || "/tmp". On Windows,HOMEis not a standard environment variable — it's set in Git Bash and WSL, but not in cmd.exe or PowerShell. This caused QMD to silently write its SQLite index toC:\tmp\.cache\qmd\(or fail entirely), instead of the user's actual home directory.Fix: Replaced with Node.js's cross-platform
os.homedir(), which correctly resolves on all platforms (Windows:C:\Users\<name>, macOS:/Users/<name>, Linux:/home/<name>).2. Feature:
QMD_GPUenvironment variablenode-llama-cpp ships pre-built CUDA binaries linked against a specific cuBLAS version. When the user's installed CUDA toolkit has a different major version (e.g., the binary needs
cublas64_13.dllbut CUDA 12.x only shipscublas64_12.dll), GPU initialization crashes withggml-cuda.cu: CUDA error. Rebuilding from source requires Visual C++ Build Tools, which many users don't have.Fix: Added
QMD_GPUenv var toensureLlama()insrc/llm.ts. Users can bypass broken CUDA with:Values:
cuda,metal,vulkan,false/off/0(CPU). When not set, behavior is unchanged (auto-detect best GPU).3. Fix: Per-session MCP HTTP transport
The HTTP server (
qmd mcp --http) previously created a singleMcpServer+WebStandardStreamableHTTPServerTransportpair at startup. All connecting clients shared this one transport, which caused session conflicts:Fix: Each
initializerequest now creates a dedicated session — its own transport and McpServer instance — tracked by session ID in aMap. All sessions share the underlying SQLite store (which is already thread-safe). On shutdown, all active sessions are closed cleanly. The/healthendpoint now reports the active session count.4. Feature: URL-based collection routing (
/mcp/COLLECTION)When QMD runs as a shared HTTP daemon (
qmd mcp --http --daemon), there's no way to pass per-project environment variables. Different projects may want to search different collections by default.Fix: The URL path now optionally includes a collection name:
/mcp/mcp/notes/mcp/work-docsThe collection name is extracted on
initializeand applied as the default for all searches in that session. The LLM instructions reflect the scoped collection name and document count.Configuration example — in per-project Claude Code settings (
.claude/settings.json):{ "mcpServers": { "qmd": { "type": "http", "url": "http://localhost:8181/mcp/my-project-docs" } } }For stdio transport, the
QMD_COLLECTIONenv var provides the same scoping.Files changed
src/store.tsprocess.env.HOME || "/tmp"→os.homedir()src/llm.tsQMD_GPUenv var inensureLlama()src/mcp.tscollectionFromPath(),resolveTransport(),createSession(),buildInstructions()collection override, health endpoint session countTest plan
tsc -p tsconfig.build.json)GET /healthreturns{ sessions: N }POST /mcpinitializes with all collections, instructions show total doc countPOST /mcp/RAMPinitializes scoped to RAMP, instructions show scoped doc count and collection nameQMD_GPU=vulkansuccessfully bypasses broken CUDA initialization